<?php
class RecsController extends AppController
{
   var  $name='Recs';
   var $layout='admin';
   var $uses=array('Rec','Site','Type');
   var $components = array('Auth');
   
   function beforeFilter()
   {
        $this->userScope = array('admin_leve'=>1);
        $this->authorize = 'controller';
        $this->Auth->loginError = '未能登录成功,密码或帐号错误';
        $this->Auth->authError='还未登录或者你没有管理员权限';
    }
    
    function isAuthorized()
    {
           if($this->Auth->user('admin_leve')>0)
            return true;
        else
            return false;
    }
    function admin_index($page=1)
    {
            $this->paginate=array(
            'page' => $page,
            'limit' =>5,
            'order' => array('Rec.created' =>  'desc')
            );
            $this->pageTitle='网址信息提交管理';
            $reclist = $this -> paginate('Rec');
            $typeTree = $this->Type->generatetreelist(null,null,null,'---');
            $this->set('tt',$typeTree);
           $this->set('rl',$reclist);
    }
    
    //删除一个网址信息
    function admin_del($id=null)
    {
        if(empty($id) or !is_numeric($id)){
            $this->flash('请指定要删除的网址信息',array('action' => 'index'),10);
            return;
        }
        if($this->Rec->del($id))
            $this->flash('删除成功','index');
         else
            $this->flash('未能删除成功','index');
    }
    
    function admin_delm($ids=0)
    {
        if(empty($ids) or $ids=='undefined'){
            $this->flash('请选择要删除的提交信息','index',5);
            return;
        }
        $idarr=explode(',',$ids);
        if($this->Rec->deleteAll(array('id' => $idarr))){
            $this->flash('成功删除多个网址',"index",5);
            return;
        }
    }
    
    function admin_moveto($id=null,$tid=0)
    {
        if(empty($id) or $id=='undefined'){
            $this->flash('请选择一个审核通过的网址信息','index',5);
            return;
        }
       if(empty($tid)){
            $this->flahs('必须给审核通过的网址信息指定一个分类');
            return;
        }
        $sites = $this->Rec->read(null,$id);
        if(empty($sites)){
            $this->flash('要审核通过的网址信息并不存在','index',5);
            return;
        }else{
           $this->data['Site']=$sites['Rec'];
            unset($this->data['Site']['user_id']);
            unset($this->data['Site']['id']);
            unset($this->data['Site']['created']);
            unset($this->data['Site']['modified']);
            $this->data['Site']['type_id']=$tid;
            $this->Site->create();
            if($this->Site->save($this->data)){
                $this->Rec->del($id);
                $this->flash("该网址信息已审核加入成功",'index',5);
                return;
            }else{
                $this->flash("该网址信息未加入成功",'index',5);
                return;
            }
        }
    }
}
?>